package com.duo.controller.user;

import com.duo.dto.UserLoginDTO;
import com.duo.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@RestController("userUserController")
@RequestMapping("/user")
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 微信登录
     * @return
     */
    @PostMapping("/login")
    public Object login(@RequestBody @Valid UserLoginDTO code, HttpServletRequest request) {
        log.info("微信用户登录：{}", code.getCode());
        String token = request.getHeader("token");
        // 微信登录
        return userService.wxLogin(code, token);
    }
}
